.class public final Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;
.super Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;
.source "NmeaUSBDevice.kt"


# instance fields
.field private final autoDisconnecter:Ljava/lang/Thread;

.field private byteArrayInputStream:Ljava/io/PipedInputStream;

.field private byteOutputStream:Ljava/io/PipedOutputStream;

.field private final configs:Llt/farmis/libraries/externalgps/providers/usb/USBDeviceManagerConfigs;

.field private final device:Landroid/hardware/usb/UsbDevice;

.field private volatile lastPoll:J

.field private volatile messagePart:Ljava/lang/String;

.field private serialPort:Lcom/felhr/usbserial/UsbSerialDevice;

.field private timeout:I

.field private final usbManager:Landroid/hardware/usb/UsbManager;

.field private final usbReadCallback:Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;


# direct methods
.method public constructor <init>(Landroid/hardware/usb/UsbDevice;Landroid/hardware/usb/UsbManager;Llt/farmis/libraries/externalgps/providers/usb/USBDeviceManagerConfigs;)V
    .locals 1

    const-string v0, "device"

    invoke-static {p1, v0}, Lkotlin/jvm/internal/Intrinsics;->checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    const-string v0, "usbManager"

    invoke-static {p2, v0}, Lkotlin/jvm/internal/Intrinsics;->checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    const-string v0, "configs"

    invoke-static {p3, v0}, Lkotlin/jvm/internal/Intrinsics;->checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    .line 15
    invoke-direct {p0}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;-><init>()V

    iput-object p1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->device:Landroid/hardware/usb/UsbDevice;

    iput-object p2, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->usbManager:Landroid/hardware/usb/UsbManager;

    iput-object p3, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->configs:Llt/farmis/libraries/externalgps/providers/usb/USBDeviceManagerConfigs;

    .line 17
    new-instance p1, Ljava/io/PipedInputStream;

    const/16 p2, 0x64

    invoke-direct {p1, p2}, Ljava/io/PipedInputStream;-><init>(I)V

    iput-object p1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->byteArrayInputStream:Ljava/io/PipedInputStream;

    .line 18
    new-instance p1, Ljava/io/PipedOutputStream;

    invoke-direct {p1}, Ljava/io/PipedOutputStream;-><init>()V

    iput-object p1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->byteOutputStream:Ljava/io/PipedOutputStream;

    const/16 p1, 0x1388

    .line 22
    iput p1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->timeout:I

    const-string p1, ""

    .line 28
    iput-object p1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->messagePart:Ljava/lang/String;

    .line 30
    new-instance p1, Ljava/lang/Thread;

    new-instance p2, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice$autoDisconnecter$1;

    invoke-direct {p2, p0}, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice$autoDisconnecter$1;-><init>(Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;)V

    const-string p3, "EXT_GPS_Disconnecter"

    invoke-direct {p1, p2, p3}, Ljava/lang/Thread;-><init>(Ljava/lang/Runnable;Ljava/lang/String;)V

    iput-object p1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->autoDisconnecter:Ljava/lang/Thread;

    .line 82
    new-instance p1, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice$usbReadCallback$1;

    invoke-direct {p1, p0}, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice$usbReadCallback$1;-><init>(Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;)V

    iput-object p1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->usbReadCallback:Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;

    return-void
.end method


# virtual methods
.method public connect()Z
    .locals 6

    .line 44
    sget-object v0, Llt/farmis/libraries/externalgps/providers/Status;->CONNECTING:Llt/farmis/libraries/externalgps/providers/Status;

    invoke-virtual {p0, v0}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->changeStatus(Llt/farmis/libraries/externalgps/providers/Status;)V

    .line 45
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->device:Landroid/hardware/usb/UsbDevice;

    const/4 v1, 0x0

    invoke-virtual {v0, v1}, Landroid/hardware/usb/UsbDevice;->getInterface(I)Landroid/hardware/usb/UsbInterface;

    move-result-object v0

    const-string v2, "device.getInterface(0)"

    invoke-static {v0, v2}, Lkotlin/jvm/internal/Intrinsics;->checkExpressionValueIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    .line 46
    iget-object v2, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->usbManager:Landroid/hardware/usb/UsbManager;

    iget-object v3, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->device:Landroid/hardware/usb/UsbDevice;

    invoke-virtual {v2, v3}, Landroid/hardware/usb/UsbManager;->openDevice(Landroid/hardware/usb/UsbDevice;)Landroid/hardware/usb/UsbDeviceConnection;

    move-result-object v2

    const/4 v3, 0x1

    .line 47
    invoke-virtual {v2, v0, v3}, Landroid/hardware/usb/UsbDeviceConnection;->claimInterface(Landroid/hardware/usb/UsbInterface;Z)Z

    .line 48
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->device:Landroid/hardware/usb/UsbDevice;

    invoke-static {v0, v2}, Lcom/felhr/usbserial/UsbSerialDevice;->createUsbSerialDevice(Landroid/hardware/usb/UsbDevice;Landroid/hardware/usb/UsbDeviceConnection;)Lcom/felhr/usbserial/UsbSerialDevice;

    move-result-object v0

    iput-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->serialPort:Lcom/felhr/usbserial/UsbSerialDevice;

    .line 50
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v4

    iput-wide v4, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->lastPoll:J

    .line 52
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->serialPort:Lcom/felhr/usbserial/UsbSerialDevice;

    const-string v2, "NMEA"

    if-eqz v0, :cond_8

    const-string v0, "serialPort != null"

    .line 53
    invoke-static {v2, v0}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 54
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->serialPort:Lcom/felhr/usbserial/UsbSerialDevice;

    const/4 v2, 0x0

    if-eqz v0, :cond_7

    invoke-virtual {v0}, Lcom/felhr/usbserial/UsbSerialDevice;->open()Z

    move-result v0

    if-eqz v0, :cond_6

    .line 56
    new-instance v0, Ljava/io/PipedInputStream;

    const/16 v1, 0x64

    invoke-direct {v0, v1}, Ljava/io/PipedInputStream;-><init>(I)V

    iput-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->byteArrayInputStream:Ljava/io/PipedInputStream;

    .line 57
    new-instance v0, Ljava/io/PipedOutputStream;

    invoke-direct {v0}, Ljava/io/PipedOutputStream;-><init>()V

    iput-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->byteOutputStream:Ljava/io/PipedOutputStream;

    .line 58
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->byteArrayInputStream:Ljava/io/PipedInputStream;

    iget-object v1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->byteOutputStream:Ljava/io/PipedOutputStream;

    invoke-virtual {v0, v1}, Ljava/io/PipedInputStream;->connect(Ljava/io/PipedOutputStream;)V

    .line 60
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->serialPort:Lcom/felhr/usbserial/UsbSerialDevice;

    if-eqz v0, :cond_5

    iget-object v1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->configs:Llt/farmis/libraries/externalgps/providers/usb/USBDeviceManagerConfigs;

    invoke-virtual {v1}, Llt/farmis/libraries/externalgps/providers/usb/USBDeviceManagerConfigs;->baudRate()I

    move-result v1

    invoke-virtual {v0, v1}, Lcom/felhr/usbserial/UsbSerialDevice;->setBaudRate(I)V

    .line 61
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->serialPort:Lcom/felhr/usbserial/UsbSerialDevice;

    if-eqz v0, :cond_4

    iget-object v1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->configs:Llt/farmis/libraries/externalgps/providers/usb/USBDeviceManagerConfigs;

    invoke-virtual {v1}, Llt/farmis/libraries/externalgps/providers/usb/USBDeviceManagerConfigs;->dataBits()I

    move-result v1

    invoke-virtual {v0, v1}, Lcom/felhr/usbserial/UsbSerialDevice;->setDataBits(I)V

    .line 62
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->serialPort:Lcom/felhr/usbserial/UsbSerialDevice;

    if-eqz v0, :cond_3

    iget-object v1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->configs:Llt/farmis/libraries/externalgps/providers/usb/USBDeviceManagerConfigs;

    invoke-virtual {v1}, Llt/farmis/libraries/externalgps/providers/usb/USBDeviceManagerConfigs;->stopBits()I

    move-result v1

    invoke-virtual {v0, v1}, Lcom/felhr/usbserial/UsbSerialDevice;->setStopBits(I)V

    .line 63
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->serialPort:Lcom/felhr/usbserial/UsbSerialDevice;

    if-eqz v0, :cond_2

    iget-object v1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->configs:Llt/farmis/libraries/externalgps/providers/usb/USBDeviceManagerConfigs;

    invoke-virtual {v1}, Llt/farmis/libraries/externalgps/providers/usb/USBDeviceManagerConfigs;->parity()I

    move-result v1

    invoke-virtual {v0, v1}, Lcom/felhr/usbserial/UsbSerialDevice;->setParity(I)V

    .line 64
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->serialPort:Lcom/felhr/usbserial/UsbSerialDevice;

    if-eqz v0, :cond_1

    iget-object v1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->configs:Llt/farmis/libraries/externalgps/providers/usb/USBDeviceManagerConfigs;

    invoke-virtual {v1}, Llt/farmis/libraries/externalgps/providers/usb/USBDeviceManagerConfigs;->flowControl()I

    move-result v1

    invoke-virtual {v0, v1}, Lcom/felhr/usbserial/UsbSerialDevice;->setFlowControl(I)V

    .line 66
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->serialPort:Lcom/felhr/usbserial/UsbSerialDevice;

    if-eqz v0, :cond_0

    iget-object v1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->usbReadCallback:Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;

    invoke-virtual {v0, v1}, Lcom/felhr/usbserial/UsbSerialDevice;->read(Lcom/felhr/usbserial/UsbSerialInterface$UsbReadCallback;)I

    .line 67
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->autoDisconnecter:Ljava/lang/Thread;

    invoke-virtual {v0}, Ljava/lang/Thread;->start()V

    .line 69
    sget-object v0, Llt/farmis/libraries/externalgps/providers/Status;->CONNECTED:Llt/farmis/libraries/externalgps/providers/Status;

    invoke-virtual {p0, v0}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->changeStatus(Llt/farmis/libraries/externalgps/providers/Status;)V

    return v3

    .line 66
    :cond_0
    invoke-static {}, Lkotlin/jvm/internal/Intrinsics;->throwNpe()V

    throw v2

    .line 64
    :cond_1
    invoke-static {}, Lkotlin/jvm/internal/Intrinsics;->throwNpe()V

    throw v2

    .line 63
    :cond_2
    invoke-static {}, Lkotlin/jvm/internal/Intrinsics;->throwNpe()V

    throw v2

    .line 62
    :cond_3
    invoke-static {}, Lkotlin/jvm/internal/Intrinsics;->throwNpe()V

    throw v2

    .line 61
    :cond_4
    invoke-static {}, Lkotlin/jvm/internal/Intrinsics;->throwNpe()V

    throw v2

    .line 60
    :cond_5
    invoke-static {}, Lkotlin/jvm/internal/Intrinsics;->throwNpe()V

    throw v2

    .line 72
    :cond_6
    sget-object v0, Llt/farmis/libraries/externalgps/providers/Status;->CONNECTING_FAILED:Llt/farmis/libraries/externalgps/providers/Status;

    invoke-virtual {p0, v0}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->changeStatus(Llt/farmis/libraries/externalgps/providers/Status;)V

    return v1

    .line 54
    :cond_7
    invoke-static {}, Lkotlin/jvm/internal/Intrinsics;->throwNpe()V

    throw v2

    :cond_8
    const-string v0, "serialPort == null"

    .line 76
    invoke-static {v2, v0}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 77
    sget-object v0, Llt/farmis/libraries/externalgps/providers/Status;->CONNECTING_FAILED:Llt/farmis/libraries/externalgps/providers/Status;

    invoke-virtual {p0, v0}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->changeStatus(Llt/farmis/libraries/externalgps/providers/Status;)V

    return v1
.end method

.method public disconnect()V
    .locals 2

    .line 103
    sget-object v0, Llt/farmis/libraries/externalgps/providers/Status;->DISCONNECTED:Llt/farmis/libraries/externalgps/providers/Status;

    invoke-virtual {p0, v0}, Llt/farmis/libraries/externalgps/providers/NMEADeviceManager;->changeStatus(Llt/farmis/libraries/externalgps/providers/Status;)V

    .line 104
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->serialPort:Lcom/felhr/usbserial/UsbSerialDevice;

    if-eqz v0, :cond_0

    new-instance v1, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice$disconnect$1;

    invoke-direct {v1, p0}, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice$disconnect$1;-><init>(Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;)V

    invoke-interface {v0, v1}, Lcom/felhr/usbserial/UsbSerialInterface;->getBreak(Lcom/felhr/usbserial/UsbSerialInterface$UsbBreakCallback;)V

    :cond_0
    return-void
.end method

.method public final getDevice()Landroid/hardware/usb/UsbDevice;
    .locals 1

    .line 15
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->device:Landroid/hardware/usb/UsbDevice;

    return-object v0
.end method

.method public final getMessagePart()Ljava/lang/String;
    .locals 1

    .line 28
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->messagePart:Ljava/lang/String;

    return-object v0
.end method

.method public final getSerialPort()Lcom/felhr/usbserial/UsbSerialDevice;
    .locals 1

    .line 20
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->serialPort:Lcom/felhr/usbserial/UsbSerialDevice;

    return-object v0
.end method

.method public final getUsbManager()Landroid/hardware/usb/UsbManager;
    .locals 1

    .line 15
    iget-object v0, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->usbManager:Landroid/hardware/usb/UsbManager;

    return-object v0
.end method

.method public final setLastPoll(J)V
    .locals 0

    .line 25
    iput-wide p1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->lastPoll:J

    return-void
.end method

.method public final setMessagePart(Ljava/lang/String;)V
    .locals 1

    const-string v0, "<set-?>"

    invoke-static {p1, v0}, Lkotlin/jvm/internal/Intrinsics;->checkParameterIsNotNull(Ljava/lang/Object;Ljava/lang/String;)V

    .line 28
    iput-object p1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->messagePart:Ljava/lang/String;

    return-void
.end method

.method public final setSerialPort(Lcom/felhr/usbserial/UsbSerialDevice;)V
    .locals 0

    .line 20
    iput-object p1, p0, Llt/farmis/libraries/externalgps/providers/usb/NmeaUSBDevice;->serialPort:Lcom/felhr/usbserial/UsbSerialDevice;

    return-void
.end method
